package com.plugin.manage.common;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.Date;

@Getter
@Setter
@ToString
public class RespObj<T> {

    private String code;
    private String msg;
    private Long timestamp;
    private T ret;

    public RespObj(String code, String msg, T ret, Long timestamp) {
        this.code=code;
        this.msg=msg;
        this.ret=ret;
        this.timestamp = timestamp;
    }

    public RespObj(BizCode code) {
        this.code = code.getCode();
        this.msg = code.getMessage();
    }


    public RespObj(){}


    public RespObj<?> success(T s) {
        return new RespObj<>(BizCode.SUCCESS.getCode(),"success", s, new Date().getTime());
    }

    public RespObj<?> success(String message) {
        return new RespObj<>(BizCode.SUCCESS.getCode(), message, null, new Date().getTime());
    }

    public RespObj<?> failure(T s) {
        return new RespObj<>(BizCode.BUSINESS_ERROR.getCode(),"failure",s,new Date().getTime());
    }

    public RespObj<?> failure(String message) {
        return new RespObj<>(BizCode.BUSINESS_ERROR.getCode(), message, null, new Date().getTime());
    }

    public RespObj<?> error(T s) {
        return new RespObj<>(BizCode.BUSINESS_ERROR.getCode(),"error",s,new Date().getTime());
    }

    public RespObj<?> error(String message) {
        return new RespObj<>(BizCode.BUSINESS_ERROR.getCode(), message, null, new Date().getTime());
    }
}
